/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren.modules.job.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.renren.modules.PCguanli.dao.LineDao;
import io.renren.modules.PCguanli.entity.LineEntity;
import io.renren.modules.app.dao.UserRegistrationDao;
import io.renren.modules.app.entity.UserRegistrationEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 测试定时任务(演示Demo，可删除)
 *
 * testTask为spring bean的名称
 *
 * @author Mark sunlightcs@gmail.com
 */
@Component("appReportTask")
public class AppReportTask implements ITask {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private LineDao lineDao;
	@Autowired
	private UserRegistrationDao userRegistrationDao;

	@Override
	public void run(String params){
		logger.info("appReportTask定时任务正在执行，参数为：{}", params);
		//凌晨01:00
		List<LineEntity> lineEntities = lineDao.selectList(new LambdaQueryWrapper<>());
		for (LineEntity entity : lineEntities) {
//			1->5 2,3->6
			if (Objects.equals(entity.getRegisterstate() , "1")) {
				entity.setRegisterstate("5");
			}else if (Objects.equals(entity.getRegisterstate() , "2")) {
				entity.setRegisterstate("6");
			}else if (Objects.equals(entity.getRegisterstate() , "3")) {
				entity.setRegisterstate("6");
			}
			else if (Objects.equals(entity.getRegisterstate() , "4")) {
				entity.setRegisterstate("6");
			}
			else if (Objects.equals(entity.getRegisterstate() , "7")) {
				entity.setRegisterstate("6");
			}
			lineDao.updateById(entity);
		}



		List<UserRegistrationEntity> userRegistrationEntities = userRegistrationDao.selectList(new LambdaQueryWrapper<>());
		for (UserRegistrationEntity entity : userRegistrationEntities) {
//			1->5 2,3->6
			if (Objects.equals(entity.getState(), "1")) {
				entity.setState("5");
			}else if (Objects.equals(entity.getState() , "2")) {
				entity.setState("6");
			}else if (Objects.equals(entity.getState() , "3")) {
				entity.setState("6");
			}else if (Objects.equals(entity.getState() , "4")) {
				entity.setState("6");
			}
			else if (Objects.equals(entity.getState() , "7")) {
				entity.setState("6");
			}

			userRegistrationDao.updateById(entity);
		}

	}
}
